using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using FlexnetConsultants.CookieNotification.Settings;
using FlexnetConsultants.CookieNotification.Code;

namespace FlexnetConsultants.CookieNotification.Features.FlexnetConsultants.CookieNotification.Admin
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("704a4084-580a-4ce4-8586-5aed795eaf18")]
    public class FlexnetConsultantsCookieNotificationEventReceiver : SPFeatureReceiver
    {

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            try
            {
                FCCookieNotificationSettings cookies = FCCookieNotificationSettings.Local;
                cookies.Update(true);
            }
            catch (Exception ex)
            {
                Logger.Current.LogException("FeatureInstalled: Unable to setup Cookie Notification Settings", ex);
            }
        }


        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            try
            {
                FCCookieNotificationSettings cookies = FCCookieNotificationSettings.Local;
                cookies.Delete();
                cookies.Unprovision();
                cookies.Uncache();
            }
            catch(Exception ex)
            {
                Logger.Current.LogException("FeatureUninstalling:Unable to remove Cookie Notification Settings", ex);
            }
        }

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}
    }
}
